package cubelabs.nexus.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import cubelabs.nexus.entity.Coupon;
import cubelabs.nexus.entity.User;

@Repository("couponDAO")
public class CouponDAO extends BaseDAO<Coupon, Long>{

	public Coupon findByCouponCode(String code){
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Restrictions.and(Restrictions.eq("code", code)));
		Coupon coupon  = (Coupon) crit.uniqueResult();
		return coupon;
	}

	public List<Coupon> findByUser(User user){
		
		List<Coupon> couponList = findByCriteria(Restrictions.eq("user", user)) ;
		return couponList;
	}

}
